Skip to content

Add Generic Header component#7061

Open
owenatgov wants to merge 3 commits into
mainfrom
generic-header
Open

Add Generic Header component#7061
owenatgov wants to merge 3 commits into
mainfrom
generic-header

Conversation

@owenatgov
Copy link
Copy Markdown
Contributor

Note

This PR is ready for review but should not be merged until we've written guidance

Change

Adds a new component: the Generic Header; a stripped back version of the GOV.UK Header for use by GOV.UK-adjacent services.

As well as adding the component, this PR changes the scaffolding of the GOV.UK Header to consume the styling and markup of the Generic Header so that both components share how they're constructed whilst continuing to be separate. Specifically:

  • the Generic Header includes 3 mixins which the GOV.UK Header builds upon
    • govuk-header-styles for the root block
    • govuk-header-logo-styles for logo area padding and box-sizing: border-box
    • govuk-header-link-styles for the logo link state styling ie: hover and focus
  • the GOV.UK Header calls the Generic Header nunjucks macro with specific modifications like the default gov.uk homepage URL and the addition of the product name

Closes #7057

Notes

The Generic header uses rounded 15px top and bottom padding, as opposed to the GOV.UK Header's magic numbers, to give users some padding to work with rather than no spacing at all. The plan is to recommend in guidance to adjust the spacing via component extension if they need to for their logos and domain/service names1.

I've removed the word-spacing rule from the Generic Header link element (and added it back in for the GOV.UK Header) which removes spacing from the root of the link element to help with spacing because I was finding for the Generic Header that it would mean users couldn't put text straight into the component's logo param. It's not clear to me if we should keep this for everything and ensure users are using child elements when adding logo html to the Generic Header.

Both headers have their own __container--full-width element modifier. It's unclear to me how wasteful this is or if both components should share one class and if so, where it would go. This could be a helper class however the thing itself is a component-level style so it's not clear where the best place for this is.

Whilst the test suites of both headers now look very similar, I think it makes sense to keep them as they are to make sure that their different contexts aren't resulting in unexpected behaviours.

@owenatgov owenatgov requested a review from a team May 18, 2026 08:03
@github-actions

This comment was marked as resolved.

@github-actions

This comment was marked as resolved.

@github-actions

This comment was marked as resolved.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 18, 2026

📋 Stats

File sizes

File Size Percentage change
dist/govuk-frontend-development.min.css 121.36 KiB 1.3%
packages/govuk-frontend/dist/govuk/govuk-frontend.min.css 121.35 KiB 1.3%

No changes to module sizes.


Action run for 0b2837c

Comment thread packages/govuk-frontend/src/govuk/components/generic-header/template.njk Outdated
@include base.govuk-font($size: 16, $line-height: 1);

// Add a transparent bottom border for forced-colour modes
border-bottom: 1px solid transparent;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will effectively make the header's padding bottom bigger so it might be that the padding should be adjusted for the generic header?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if I tried to maintain the generic nature of the padding by adding something like govuk-spacing(3) - 1px to account for that invisible border?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm thinking the 'magic' that's in the gov.uk logo is probably some part based on this border here and then a few pixels just down to the logo itself.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After playing around with this it's a bit trickier than I thought. If I take away a px from the bottom padding, it means that now the logo is no longer 60px in height like the GOV.UK header (61px with that border). If I add a px to the top then by my eye it looks top heavy:

Generic header with 16px top padding and 14px bottom padding, functionally 15px

Looking at it again with 15px top and 15px bottom, functionally 16px bottom... I think it looks ok?

Generic header with 15px top padding and 15px bottom padding, functionally 16px

This might be a line height thing. Either way I've run this past @mia-allers-gds and she's happy with it staying as is. I'll again make a note of this during testing to see if it comes up again with other dept logos.

Comment thread packages/govuk-frontend/src/govuk/components/generic-header/generic-header.yaml Outdated
Comment thread packages/govuk-frontend/src/govuk/components/generic-header/_mixin.scss Outdated
Comment thread packages/govuk-frontend-review/src/images/generic-header/hmlr-logo.png Outdated
Comment thread packages/govuk-frontend/src/govuk/components/_index.scss
Comment thread packages/govuk-frontend/src/govuk/components/_index.import.scss
Comment thread packages/govuk-frontend/src/govuk/components/generic-header/_mixin.scss Outdated
Comment thread packages/govuk-frontend/src/govuk/components/generic-header/_mixin.scss Outdated
Comment thread packages/govuk-frontend/src/govuk/components/generic-header/README.md Outdated
Comment thread packages/govuk-frontend/src/govuk/components/generic-header/template.njk Outdated
{% block pageTitle %}HM Pizza Finder{% endblock %}

{% set logoContent %}
<svg width="28" height="30" viewBox="0 0 28 30" fill="none" xmlns="http://www.w3.org/2000/svg">
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<svg width="28" height="30" viewBox="0 0 28 30" fill="none" xmlns="http://www.w3.org/2000/svg">
<svg width="28" height="30" viewBox="0 0 28 30" fill="currentColor" xmlns="http://www.w3.org/2000/svg">

If we set the svg to current color and remove the fill attribute from the circles it'll change colour alongside the text, for example, when the link is focused

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also less important but you can remove transforms and save a few bytes by doing this:

https://stackoverflow.com/a/24180005

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a generic header component

5 participants